package com.alageek.study.controller;

import com.alageek.study.entity.Author;
import com.alageek.study.entity.Book;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RestController;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;

@RestController
public class GlobalController {
    @GetMapping("/getMap")
    public void getMap(Model model){
        Map<String, Object> map = model.asMap();
        Set<String> keySet = map.keySet();
        Iterator<String> iterator = keySet.iterator();
        while(iterator.hasNext()){
            String key = iterator.next();
            Object value = map.get(key);
            System.out.println(key + ">>>>>>" + value);
        }
    }

    @GetMapping("/book")
    public String book(@ModelAttribute("b")Book book, @ModelAttribute("a")Author author){
        return book.toString() + " >>> " + author.toString();
    }
}
